

<script>
export default {
  props: {
    obj: {},
  },
  data() {
    return {
      readerObj: {},
      // 默认渲染obj对象
      attrObj: "obj",
      //  // 默认渲染innerHTML属性
      attr: "innerHTML",
    };
  },
  name: "reader",
  render(h) {
    // console.log(this.obj, "1111111");

    // 是字符串时，生成一个对象
    if (!(this.obj instanceof Object)) {
      this.readerObj.tag = "p"; //如果后期要接在后面把p 换成span即可
      this.readerObj.content = this.obj;

      this.attrObj = "readerObj";
    }
    // 没tag就动态加一个
    if (!this[this.attrObj]?.tag) {
      this[this.attrObj].tag = "p";
    }

    // 是否为图片标签
    if (this[this.attrObj]?.tag == "img") {
      this.attr = "src";
    }
    console.log(this.obj, "出来");
    // 渲染数据
    return h(
      `${this[this.attrObj].tag}`,
      {
        domProps: {
          [this.attr]: this[this.attrObj].content,
        },
      },
      this[this.attrObj].content
    );
  },
};
</script>

<style>
ul li {
  list-style: unset;
}
</style>